package artid.com.arttogoa.util;

import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.animation.AnticipateOvershootInterpolator;

import artid.com.arttogoa.R;
import artid.com.arttogoa.adapter.StrericWheelAdapter;
import artid.com.arttogoa.parser.ClassesPrser;
import artid.com.arttogoa.parser.ClasslistParse.Classlist;
import artid.com.arttogoa.task.CallbackSky;
import artid.com.arttogoa.view.WheelView;

public class AlumAlert {
	private static WheelView wheelView;
	private static AlertDialog alertDialog;

	@SuppressWarnings("unused")
	public static void initAlertDialog(Activity mContext, List<Classlist> Data,
			final CallbackSky onclick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_type, null);
		wheelView = (WheelView) view.findViewById(R.id.timeWheel);
		String[] data = new String[Data.size()];
		for (int i = 0; i < data.length; i++) {
			data[i] = Data.get(i).getName();
		}
		wheelView.setAdapter(new StrericWheelAdapter(data));
		wheelView.setCurrentItem(2);
		wheelView.setCyclic(false);
		wheelView.setInterpolator(new AnticipateOvershootInterpolator());

		view.findViewById(R.id.btnCancel).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
					}
				});
		view.findViewById(R.id.btnConfirm).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						onclick.callBack(Integer.valueOf(wheelView
								.getCurrentItem()));
						dismiss();
					}
				});

		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();

		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = mContext.getWindowManager().getDefaultDisplay()
				.getWidth();
		int height = mContext.getWindowManager().getDefaultDisplay()
				.getHeight();
		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.BOTTOM;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);

	}

	@SuppressWarnings("unused")
	public static void initAgeAlertDialog(Activity mContext, String[] data,
			final CallbackSky onclick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_type, null);
		wheelView = (WheelView) view.findViewById(R.id.timeWheel);
		wheelView.setAdapter(new StrericWheelAdapter(data));
		wheelView.setCurrentItem(0);
		wheelView.setCyclic(false);
		wheelView.setInterpolator(new AnticipateOvershootInterpolator());

		view.findViewById(R.id.btnCancel).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
					}
				});
		view.findViewById(R.id.btnConfirm).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						onclick.callBack(Integer.valueOf(wheelView
								.getCurrentItem()));
						dismiss();
					}
				});

		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();

		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = mContext.getWindowManager().getDefaultDisplay()
				.getWidth();
		int height = mContext.getWindowManager().getDefaultDisplay()
				.getHeight();
		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.BOTTOM;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);

	}
	
	/**
	 * 艺术家类别选择器
	 * @param mContext
	 * @param Data
	 * @param onclick
	 */
	public static void initAlertClassesDialog(Activity mContext, List<ClassesPrser> Data,
			final CallbackSky onclick) {
		View view = LayoutInflater.from(mContext).inflate(
				R.layout.pop_menu_type, null);
		wheelView = (WheelView) view.findViewById(R.id.timeWheel);
		String[] data = new String[Data.size()];
		for (int i = 0; i < data.length; i++) {
			data[i] = Data.get(i).getAname();
		}
		wheelView.setAdapter(new StrericWheelAdapter(data));
		wheelView.setCurrentItem(0);
		wheelView.setCyclic(false);
		wheelView.setInterpolator(new AnticipateOvershootInterpolator());

		view.findViewById(R.id.btnCancel).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						dismiss();
					}
				});
		view.findViewById(R.id.btnConfirm).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						// TODO Auto-generated method stub
						onclick.callBack(Integer.valueOf(wheelView
								.getCurrentItem()));
						dismiss();
					}
				});

		alertDialog = new AlertDialog.Builder(mContext).create();
		alertDialog.show();

		WindowManager.LayoutParams params = alertDialog.getWindow()
				.getAttributes();
		params.width = mContext.getWindowManager().getDefaultDisplay()
				.getWidth();
		int height = mContext.getWindowManager().getDefaultDisplay()
				.getHeight();
		params.height = LayoutParams.WRAP_CONTENT;
		params.gravity = Gravity.BOTTOM;

		Window window = alertDialog.getWindow();
		window.setAttributes(params);
		window.setContentView(view);
		alertDialog.getWindow().setContentView(view);

	}

	public static void dismiss() {
		// TODO Auto-generated method stub
		if (alertDialog != null && alertDialog.isShowing()) {
			alertDialog.dismiss();
			alertDialog = null;
		}
	}
}
